package customer.zspt.cn.customer.Adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

import customer.zspt.cn.customer.components.chat.chatQuiteVp.BaseVpItem;

/**
 * Created by Administrator on 2018/7/23 0023.
 */

public class ChatQuitePageAdapter extends PagerAdapter {
    List<BaseVpItem> mVpData;
    Context mContext;
    public ChatQuitePageAdapter(List<BaseVpItem> VpData,Context context){
        mVpData = VpData;
        mContext = context;
    }
    @Override
    public int getCount() {
        return mVpData.size();
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        final View mRootView = mVpData.get(position).mRootView;
        mVpData.get(position).getBasicDataLintener(new BaseVpItem.BasicDataLintener() {
            @Override
            public void getData(Object data) {
                 if(mLintener!=null){
                     mLintener.getData(data);
                 }
            }
        });
        container.addView(mRootView);
        return mRootView;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view==object;
    }
    public BasicItemDataLintener mLintener;
    public void getBasicItemDataLintener(BasicItemDataLintener lintener){
        mLintener = lintener;
    }
     public interface BasicItemDataLintener{
            void getData(Object data);
        }
}
